<?php
/**
 * 
 * @author Administrator
 *
 */
class LoginAction extends Action{
	
	public function index(){
		$this->display();
	}
	
	public function verify(){
		import('Class.Image',APP_PATH);
		Image::buildImageVerify();
	}
	
	public function login(){
		if (!IS_POST) {
			halt("页面不存在");
		}
		if (md5(strtolower(I('verify')))!=session('verify')) {
			$this->error("验证码错误");
		}
		$db=M('user');
		$arr=array(
				'username'=>I('username'),
				'password'=>md5(I('password'))
		);
		$user=$db->where($arr)->find();
		 if (!$user) {
		 	 $this->error("账号或密码错误");
		 }else{
		 	$data=array(
		 			'id'=>$user['id'],
		 			'logintime'=>time(),
		 			'loginip'=>get_client_ip()
		 	);
		 	$db->save($data);
		 	 
		 	
		 	session('uid',$user['id']);
		 	session('username',$user['username']);
		 	session('lastip',$user['loginip']);
		 	session('lastvisit',date('Y-m-d H:i:s',$user['logintime']));
		 	redirect(__GROUP__);
		 }
		 
		 
	}
	/**
	 * 退出系统
	 */
	public function logout(){
		session_unset();
		session_destroy();
		$this->redirect(GROUP_NAME.'/Index/index');
	
	}
}
?>